package com.myjob;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {

    String tag = "hms";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        request();
    }

    private void request() {
        //第一步：创建一个retrofit的对象
        final Retrofit mRetrofit = new Retrofit.Builder()
                .baseUrl("http://fy.iciba.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //第二步：创建请求接口的实例
        NetInterface mInterface = mRetrofit.create(NetInterface.class);
        //第三步：对发送请求进行封装
        Call<Translation> mCall = mInterface.getCall();
        //第四步：发送请求
        mCall.enqueue(new Callback<Translation>() {
            @Override
            public void onResponse(Call<Translation> call, Response<Translation> r) {
                Log.e(tag, r.body().getStatus() +
                        r.body().getContent().getFrom() +
                        r.body().getContent().getOut());
            }

            @Override
            public void onFailure(Call<Translation> call, Throwable t) {
            }
        });
    }
}
